Import-Module PSWriteHTML
# Dynamically pulling the DHCP servers in a Active Directory domain
$DHCP_Servers = Get-DhcpServerInDC | Sort-Object -Property DnsName
$Output = Foreach ($DHCP_Server in $DHCP_Servers) {
    # Going through the DHCP servers that were returned one at a time to pull statistics
    try {
        $DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName $DHCP_Server.DNSName -ErrorAction Stop
    } catch {
        Write-Warning "Couldn't reach server $($DHCP_Server.DNSName)"
        $DHCP_Scopes = $Null
    }
    Foreach ($DHCP_Scope in $DHCP_Scopes) {
        # Going through the scopes returned in a given server
        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCP_Server.DNSName -ScopeId $DHCP_Scope.ScopeId
        [PSCustomObject] @{
            'DHCP Server'    = $DHCP_Server.DNSName
            'DHCP IP'        = $DHCP_Server.IPAddress
            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString
            'Scope Name'     = $DHCP_Scope.Name
            'Scope State'    = $DHCP_Scope.State
            'In Use'         = $DHCP_Scope_Stats.InUse
            'Free'           = $DHCP_Scope_Stats.Free
            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))
            'Reserved'       = $DHCP_Scope_Stats.Reserved
            'Subnet Mask'    = $DHCP_Scope.SubnetMask
            'Start Range'    = $DHCP_Scope.StartRange
            'End Range'      = $DHCP_Scope.EndRange
            'Lease Duration' = $DHCP_Scope.LeaseDuration
        }
    }
}
$Output | Format-Table